﻿using System;
using System.Collections.Generic;

namespace Lasalara.Model
{
    public class Book : IEquatable<Book>
    {
        public string Name { get; set; }
        public string Title { get; set; }
        public string Bk { get; set; }
        public string Email { get; set; }
        public string Dr { get; set; }
        public string Institution { get; set; }
        public List<Chapter> Chapters { get; set; }
        public bool IsDownloaded { get; set; }
        public double Progress { get; set; }

        public string EmailOrInstitution
        {
            get
            {
                if (!string.IsNullOrEmpty(Institution))
                {
                    if (!string.IsNullOrEmpty(Name))
                    {
                        return Name + ", " + Institution;
                    } else
                    {
                        return Institution;
                    }
                }
                return Email;
            }
        }

        public string ProgressPercentage
        {
            get
            {
                if (Progress > 0 && Progress < 1)
                {
                    return IsDownloaded ? "< 1%" : "";
                }
                else
                {
                    return IsDownloaded ? string.Format("{0}{1}", Math.Round(Progress, 0), "%") : "";
                }
            }
        }

        #region IEquatable<Book> Members

        /// <summary>
        /// Checks if given book's key equals to this book's key
        /// </summary>
        /// /// <param name="other">Given book</param>
        public bool Equals(Book other)
        {
            return other != null && Bk.Equals(other.Bk);
        }

        #endregion
    }
}